home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-taruty.ads < prev    next >
Text File  |  1994-05-19  |  18KB  |  407 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --          S Y S T E M . T A S K I N G . R U N T Y P E _ T Y P E S         --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.6 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1991,1992,1993, FSU, All Rights Reserved         --
  12. --                                                                          --
  13. --  GNARL is free software; you can redistribute it and/or modify it  under --
  14. --  terms  of  the  GNU  Library General Public License as published by the --
  15. --  Free Software Foundation; either version 2,  or (at  your  option)  any --
  16. --  later  version.   GNARL is distributed in the hope that it will be use- --
  17. --  ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
  18. --  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. --  eral Library Public License for more details.  You should have received --
  20. --  a  copy of the GNU Library General Public License along with GNARL; see --
  21. --  file COPYING. If not, write to the Free Software Foundation,  675  Mass --
  22. --  Ave, Cambridge, MA 02139, USA.                                          --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Unchecked_Conversion;
  27.  
  28. package System.Tasking.Runtime_Types is
  29.  
  30.    --  Entry queue related types
  31.  
  32.    type Server_Kind is (Task_Server, PO_Server);
  33.  
  34.    type Server_Record (Kind : Server_Kind := Task_Server) is record
  35.       case Kind is
  36.          when Task_Server =>
  37.             Called_Task : Task_ID;
  38.             Acceptor_Prev_Call : Entry_Call_Link;
  39.  
  40.             Acceptor_Prev_Priority : Rendezvous_Priority;
  41.             --  For a task servicing a task entry call,
  42.             --  information about the most recent prior call being serviced.
  43.             --   Not used for protected entry calls;
  44.             --  this function should be performed by GNULLI ceiling locking.
  45.  
  46.          when PO_Server =>
  47.             Called_PO : Protection_Access;
  48.  
  49.       end case;
  50.    end record;
  51.  
  52.    --  Protected Objects related definitions
  53.  
  54.    Null_PO : constant Protection_Access := null;
  55.  
  56.    --  ATCB type defintions
  57.  
  58.    type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index);
  59.  
  60.    type ATCB_Ptr is access Ada_Task_Control_Block;
  61.  
  62.    All_Tasks_List : ATCB_Ptr;
  63.    All_Tasks_L : Task_Primitives.Lock;
  64.  
  65.    function ID_To_ATCB is new
  66.      Unchecked_Conversion (Task_ID, ATCB_Ptr);
  67.  
  68.    function ATCB_To_ID is new
  69.      Unchecked_Conversion (ATCB_Ptr, Task_ID);
  70.  
  71.    function ATCB_To_Address is new
  72.      Unchecked_Conversion (ATCB_Ptr, System.Address);
  73.  
  74.    type Task_Stage is (
  75.       Created,
  76.       --  Task has been created but has not begun activation.
  77.  
  78.       Can_Activate,
  79.       --  Task has begin activation.
  80.  
  81.       Active,
  82.       --  Task has completed activation and is executing the task body.
  83.  
  84.       Await_Dependents,
  85.       --  Task is waiting for all of its dependents to become passive (be
  86.       --  complete, terminated, or be waiting on a terminate alternative).
  87.  
  88.       Passive,
  89.       --  The task is passive.
  90.  
  91.       Completing,
  92.       --  The task is committed to becoming complete, but has not yet
  93.       --  satisfied all of the conditions for completion.  This
  94.       --  acts as a claim to completion; once Stage is set to this value,
  95.       --  no other task can continue with completion.
  96.  
  97.       Complete,
  98.       --  The task is complete.  The task and all of its dependents are
  99.       --  passive; some dependents may still be waiting on terminate
  100.       --  alternatives.
  101.  
  102.       Terminated);
  103.       --  The task is terminated.  All dependents waiting on terminate
  104.       --  alternatives have been awakened and have terminated themselves.
  105.  
  106.    type Accepting_State is (
  107.       Not_Accepting,   --  task is not ready to accept any entry call
  108.       Trivial_Accept,   --  "accept E;"
  109.       Simple_Accept,    --  "accept E do ... end E;"
  110.       Select_Wait);     --  most general case
  111.  
  112.    type Entry_Call_Array is array (ATC_Level_Index) of
  113.      aliased Entry_Call_Record;
  114.  
  115.    type Entry_Queue_Array is array (Task_Entry_Index range <>) of Entry_Queue;
  116.  
  117.    --  Notes on protection (synchronization) of TRTS data structures.
  118.  
  119.    --  Any field of the TCB can be written by the activator of a task when the
  120.    --  task is created, since no other task can access the new task's
  121.    --  state until creation is complete.
  122.  
  123.    --  The protection for each field is described in a comment starting with
  124.    --  "Protection:".
  125.  
  126.    --  When a lock is used to protect an ATCB field, this lock is simply named.
  127.  
  128.    --  Some protection is described in terms of tasks related to the
  129.    --  ATCB being protected.  These are:
  130.  
  131.    --    Self: The task which is controlled by this ATCB.
  132.    --    Acceptor: A task accepting a call from Self.
  133.    --    Caller: A task calling an entry of Self.
  134.    --    Parent: The task executing the master on which Self depends.
  135.    --    Dependent: A task dependent on Self.
  136.    --    Activator: The task that created Self and initiated its activation.
  137.    --    Created: A task created and activated by Self.
  138.  
  139.    type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index) is record
  140.  
  141.       LL_TCB : aliased Task_Primitives.Task_Control_Block;
  142.       --  Control block used by the underlying low-level tasking service
  143.       --  (GNULLI).
  144.       --  Protection: This is used only by the GNULLI implementation, which
  145.       --  takes care of all of its synchronization.
  146.  
  147.       Task_Entry_Point : Init_State;
  148.       --  Information needed to call the procedure containing the code for
  149.       --  the body of this task.
  150.       --  Protection: Part of the synchronization between Self and
  151.       --  Activator.  Activator writes it, once, before Self starts
  152.       --  executing.  Self reads it, once, as part of its execution.
  153.  
  154.       Task_Arg : System.Address;
  155.       --  The argument to to task procedure.  Currently unused; this will
  156.       --  provide a handle for discriminant information.
  157.       --  Protection: Part of the synchronization between Self and
  158.       --  Activator.  Activator writes it, once, before Self starts
  159.       --  executing.  Thereafter, Self only reads it.
  160.  
  161.       Stack_Size : Size_Type;
  162.       --  Requested stack size.
  163.       --  Protection: Only used by Self.
  164.  
  165.       Current_Priority : System.Priority;
  166.       --  Active priority, except that the effects of protected object
  167.       --  priority ceilings are not reflected.  This only reflects explicit
  168.       --  priority changes and priority inherited through task activation
  169.       --  and rendezvous.
  170.       --  Ada 9X notes: In Ada 9X, this field will be transferred to the
  171.       --  Priority field of an Entry_Calls componant when an entry call
  172.       --  is initiated.  The Priority of the Entry_Calls componant will not
  173.       --  change for the duration of the call.  The accepting task can
  174.       --  use it to boost its own priority without fear of its changing in
  175.       --  the meantime.
  176.       --  This can safely be used in the priority ordering
  177.       --  of entry queues.  Once a call is queued, its priority does not
  178.       --  change.
  179.       --  Since an entry call cannot be made while executing
  180.       --  a protected action, the priority of a task will never reflect a
  181.       --  priority ceiling change at the point of an entry call.
  182.       --  Protection: Only written by Self, and only accessed when Acceptor
  183.       --  accepts an entry or when Created activates, at which points Self is
  184.       --  suspended.
  185.  
  186.       L : Task_Primitives.Lock;
  187.       --  General purpose lock; protects most fields in the ATCB.
  188.  
  189.       Compiler_Data :